package com.tju.ocean_ecology_website.dto;

import com.tju.ocean_ecology_website.entity.TeamMember;
import com.tju.ocean_ecology_website.entity.User;
import lombok.Data;

import java.util.Date;

/**
 * 队伍成员DTO
 */
@Data
public class TeamMemberDTO {

    /**
     * 成员ID
     */
    private Long id;

    /**
     * 用户ID
     */
    private Long userId;

    /**
     * 用户名
     */
    private String username;

    /**
     * 姓名
     */
    private String name;

    /**
     * 头像
     */
    private String avatar;

    /**
     * 加入时间
     */
    private Date joinTime;

    /**
     * 成员角色：0-领导者, 1-管理员, 2-普通成员
     */
    private Integer role;

    /**
     * 成员状态：0-活跃, 1-非活跃
     */
    private Integer status;

    /**
     * 审核状态：0-待审核, 1-已通过, 2-已拒绝
     */
    private Integer auditStatus;

    /**
     * 拒绝原因
     */
    private String rejectReason;

    /**
     * 邮箱
     */
    private String email;

    /**
     * 电话
     */
    private String phone;

    /**
     * 从用户和团队成员信息构建DTO
     */
    public static TeamMemberDTO fromUserAndTeamMember(User user, TeamMember teamMember) {
        TeamMemberDTO dto = new TeamMemberDTO();

        if (teamMember != null) {
            dto.setId(teamMember.getId());
            dto.setUserId(teamMember.getUserId());
            dto.setJoinTime(teamMember.getJoinTime());
            dto.setRole(teamMember.getRole());
            dto.setStatus(teamMember.getStatus());
            dto.setAuditStatus(teamMember.getAuditStatus());
            dto.setRejectReason(teamMember.getRejectReason());
        }

        if (user != null) {
            dto.setUsername(user.getUsername());
            dto.setName(user.getName());
            dto.setAvatar(user.getAvatar());
            dto.setEmail(user.getEmail());
            dto.setPhone(user.getPhone());
        }

        return dto;
    }
}
